#
# @lc app=leetcode.cn id=696 lang=python
#
# [696] 计数二进制子串
#

# @lc code=start
class Solution(object):
    def countBinarySubstrings(self, s):
        """
        :type s: str
        :rtype: int
        """
        # 算出每个0或者1连续的个数，然后取两个之间小的那个个数相加
        counts=[]
        cur=1
        for i in range(1,len(s)):
            if s[i]==s[i-1]:
                cur+=1
            else :
                counts.append(cur)
                cur=1
        counts.append(cur)
        res=sum(min(counts[i],counts[i+1]) for i in range(len(counts)-1))
        return res
# @lc code=end

